package com.matthicks.macrobot;
import java.io.IOException;
import java.io.OutputStream;

import javax.swing.text.Document;
import javax.swing.text.Style;

public class StyledOutputStream extends OutputStream {
	private Document document;
	private Style style;
	private StringBuffer buffer;
	
	public StyledOutputStream(Document document, Style style) {
		super();
		this.document = document;
		this.style = style;
		buffer = new StringBuffer();
	}
	
	public void write(int b) throws IOException {
		char c = (char)b;
		try {
			if (c == '\r') {
				// Ignore
			} else if (c == '\n') {
				//document.insertString(document.getLength(), buffer.toString() + "\n", style);
				Macrobot.get().writeLine(style, buffer.toString());
				buffer = new StringBuffer();
			} else {
				buffer.append(c);
			}
		} catch(Exception exc) {
			// Can't do anything
		}
	}

}
